package edu.ahut.corejava2;

import java.util.HashMap;
import java.util.Map;

public class TestMap {
    //Map 关联容器 ，作为两列的内存数据库  CRUD
    public static void main(String[] args) {
        Map<String, String> contacts = new HashMap<>();//初始化map

        contacts.put("tom", "123456789000");//插入
        contacts.put("cat", "1234");//插入
        contacts.put("jerry", "999");//插入
        System.out.println("Calling " + contacts.get("tom"));
        contacts.put("tom", "77777777777777");//Update
        System.out.println("Calling " + contacts.get("tom"));
        contacts.remove("tom");//delete
        System.out.println("Calling " + contacts.get("tom"));


        System.out.println(contacts.keySet());
        System.out.println(contacts.values());
        System.out.println(contacts);
        for (String name : contacts.keySet()) {
            System.out.println(name + " " + contacts.get(name));
        }
        contacts.forEach((k, v) -> {
            System.out.println(k + " " + v);
        });

    }
}
